import { navigateTo } from '@tarojs/taro';
import { storeToRefs } from 'pinia';
import { useAuthStore, } from '@/store';
import { useRouterPush } from '@/composables';
import { showToast } from '@tarojs/taro';
import { useEmitter } from '@/hooks/common';


export function toHospital() {
    const emitter = useEmitter();

    const { nurseUser, openid } = storeToRefs(useAuthStore())

    const { resetAuthStore } = useAuthStore()
    if (nurseUser?.value?.id && nurseUser?.value?.defaultHospital && openid?.value) {
        navigateTo({
            url: '/package-home/hospital/index'
        });
    } else if (nurseUser?.value?.id && openid?.value) {
        showToast({
            title: "请先选择医院！",
            icon: 'none',
            duration: 1000
        });
        emitter.$emit("select_hospital")
    } else {
        showToast({
            title: "请先登录！",
            icon: 'none',
            duration: 1000
        });
        setTimeout(() => {
            const { toLogin } = useRouterPush();
            resetAuthStore();
            toLogin();
        }, 1000);

    }
}

export function toGohome() {
    navigateTo({
        url: '/package-home/gohome/index'
    });
}

export function toCompanion() {
    navigateTo({
        url: '/package-home/companion/index'
    });
}

export function toSingleService() {

    const { nurseUser, openid } = storeToRefs(useAuthStore())
    const emitter = useEmitter();
    const { resetAuthStore } = useAuthStore()
    if (nurseUser?.value?.id && nurseUser?.value?.defaultHospital && openid?.value) {
        navigateTo({
            url: '/package-home/singleservice/index'
        });

    } else if (nurseUser?.value?.id && openid?.value) {
        showToast({
            title: "请先选择医院！",
            icon: 'none',
            duration: 1000
        });
        emitter.$emit("select_hospital")
    } else {
        showToast({
            title: "请先登录！",
            icon: 'none',
            duration: 1000
        });
        setTimeout(() => {
            const { toLogin } = useRouterPush();
            resetAuthStore();
            toLogin();
        }, 1000);

    }
}

export function toShare() {
    navigateTo({
        url: '/package-home/share/index'
    });
}
export function toMotherBaby() {
    navigateTo({
        url: '/package-home/mother-baby/index'
    });
}

export function toInformation(id: string) {
    navigateTo({
        // url: `/package-home/information/index?id=${id}`
        url: `/package-other/articles/index?id=${id}`
    });
}

export function toArticles() {
    navigateTo({
        url: '/package-home/articles/index'
    });
}

export function toVideos() {
    navigateTo({
        url: '/package-home/videos/index'
    });
}

